package pers.wq.model.dao;

import java.util.List;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.transaction.annotation.Transactional;

public class QueryDao{
	public static List<Map<String,Object>> selectQuery(String str){
		List<Map<String,Object>> reList = null;
		
		try {
			Session session = HibernateUtil.getSession();
			reList = session.createSQLQuery(str).setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP).list();
			//System.out.println(reList);
			//session.flush();
			session.close();
		}catch(Exception e) {
			e.printStackTrace();
			reList = null;
		}
		return reList;
	}
	
	@Transactional
	public static boolean query(String str){
		boolean reb = true;
		try {
			System.out.println("QueryDao : " + str);
			Session session = HibernateUtil.getSession();
			session.beginTransaction(); 
			session.createSQLQuery(str).executeUpdate();
			//System.out.println(reList);
			//session.flush();
			session.getTransaction().commit();
			session.close();
		}catch(Exception e) {
			//e.printStackTrace();
			return false;
		}
		return reb;
	}
	
}
